package cn.xwj.poiExcle;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by thinkjoy on 2017/6/19.
 * 从Excel导入数据
 */
public class PoIExcelOutPut {

    public List<ScoreInfo> loadScoreInfo(String xlsPath) throws IOException{
        List temp=new ArrayList();
        FileInputStream inputStream=new FileInputStream(xlsPath);
        Workbook wb=new HSSFWorkbook(inputStream);
        Sheet sheet=wb.getSheetAt(0);
        for(Row r:sheet){
            if(r.getRowNum()<2){
                continue;
            }
            ScoreInfo scoreInfo=new ScoreInfo();
            scoreInfo.setUsername(r.getCell(0).getStringCellValue());
            scoreInfo.setClassname(r.getCell(1).getStringCellValue());
            scoreInfo.setRscore(r.getCell(2).getStringCellValue());
            scoreInfo.setMscore(r.getCell(3).getStringCellValue());
            temp.add(scoreInfo);
        }
        inputStream.close();
        return temp;
    }
}
